package com.zhihao.domain.strategy.service.rule.tree.factory;

import com.zhihao.domain.strategy.model.valobj.RuleLogicCheckTypeVO;
import com.zhihao.domain.strategy.model.valobj.RuleTreeVO;
import com.zhihao.domain.strategy.service.rule.tree.ILogicTreeNode;
import com.zhihao.domain.strategy.service.rule.tree.factory.engine.IDecisionTreeEngine;
import com.zhihao.domain.strategy.service.rule.tree.factory.engine.impl.DecisionTreeEngine;
import lombok.*;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author Jackson
 * @description 规则树工厂:负责创建、engine引擎负责一些执行逻辑
 * @create 2024-01-27 11:28
 */
@Service
public class DefaultTreeFactory {

    /* 规则树的每个节点都代表一个‘过滤规则’：rule_lock(根节点)、rule_stock(库存)、rule_luck_award(兜底奖励)-叶子节点 */
    private final Map<String, ILogicTreeNode> logicTreeNodeGroup;

    public DefaultTreeFactory(Map<String, ILogicTreeNode> logicTreeNodeGroup) {
        this.logicTreeNodeGroup = logicTreeNodeGroup;
    }

    public IDecisionTreeEngine openLogicTree(RuleTreeVO ruleTreeVO) {
        return new DecisionTreeEngine(logicTreeNodeGroup, ruleTreeVO);
    }

    /**
     * 决策树个动作实习
     */
    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class TreeActionEntity {
        /* 放行/接管 */
        private RuleLogicCheckTypeVO ruleLogicCheckType;
        /* 奖品Id+奖品配置规则 */
        private StrategyAwardVO strategyAwardVO;
    }

    @Data
    @Builder
    @AllArgsConstructor
    @NoArgsConstructor
    public static class StrategyAwardVO {
        /** 抽奖奖品ID - 规则树 内部流转使用 */
        private Integer awardId;
        /** 抽奖奖品规则 */
        private String awardRuleValue;
    }

}
